from django.core.management.base import BaseCommand, CommandError
from connie2_django.connie2.interact import invokeConnieProcess
import os.path as op

class Command(BaseCommand):
    help = "Invoke connie via the webapp infrastructure, for a given input file."
    args = "<input file>"

    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError, "Must specify exactly one argument, the input file to use."

        inpfile = args[0]
        if not op.exists(inpfile):
            raise CommandError, "Can't find input file '%s'" % inpfile

        with open(inpfile, 'r') as f:
            inpstr = f.read()

            outdata = invokeConnieProcess(inpstr)

            return outdata

        return '<Something must have gone wrong, sorry; you should have seen an error.>'
